/*
 * @Author : restyhap
 * @Date   : 2023-01-23 20:22:40
 * @LastEditors: restyhap
 * @LastEditTime: 2023-01-23 20:33:38
 */
const fs = require('fs');
const path = require('path');

/**
 * 获取 data 数据
 * @param {vscode.TextEditor} textEditor vscode 中的编辑器
 * @returns 对应文件的 data 数据
 */
function getTypeData (textEditor) {
  let typeData = JSON.parse(fs.readFileSync(path.join(__dirname, "type.json"), { encoding: "utf8" })).data;
  // 获取当前文件后缀, 以确定是否对当前行进行操作。
  let currentFileName = textEditor.document.fileName;
  let currentSuffix = currentFileName.substring(currentFileName.lastIndexOf(".") + 1, currentFileName.length);
  let data = {};
  for (let i = 0; i < typeData.length; i++) {
    if (currentSuffix == typeData[i].fileSuffix) {
      data = typeData[i];
      break;
    }
  }
  return data;
}

module.exports = {
  getTypeData
}